package jjn.daily;

/**
 * @author Jjn
 * @since 2023/7/11 18:43
 */
public class LeetCode1911 {
    public long maxAlternatingSum(int[] nums) {
        long even = nums[0], odd = 0;
        for (int i = 1; i < nums.length; i++) {
            even = Math.max(even, odd + nums[i]);
            odd = Math.max(odd, even - nums[i]);
        }
        return even;
    }
    
    public static void main(String[] args) {
        long maxAlternatingSum = new LeetCode1911().maxAlternatingSum(new int[]{6, 2, 1, 2, 4, 5});
        System.out.println("maxAlternatingSum = " + maxAlternatingSum);
    }
}
